<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
    <title>upp</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" th:href="@{/front/js/layui/css/layui.css}" type="text/css">
</head>
<body>

<form class="layui-form" th:action="@{/user/update}" style="padding-top: 10px; padding-right: 50px;">
    <input hidden name="uid" th:value="${param.uid}">
    <!--标题-->
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="username" th:value="${param.username}" required  lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="text" name="upassword" th:value="${param.upassword}" required  lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>

    <!--提交、重置按钮-->
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script th:src="@{/front/js/layui/layui.js}"></script>

<script>
    layui.use(['form', 'upload', 'jquery'], function(){
        const form = layui.form;
        const $ = layui.jquery;

        //监听提交
        form.on('submit(formDemo)', function(data){
            $.ajax({
                url : $('form').attr('action'),
                type : 'POST',
                cache : false,
                data : new FormData($('form')[0]),
                processData : false,
                contentType : false,
                success : function(result) {

                    parent.layui.table.reload("demo", {
                        page: {curr: 1}
                    });
                    //上传成功后的回调方法
                    let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
                }
            });
            return false;
        });
    });
</script>
</body>
</html>
